package com.edu.controller;


import com.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.edu.entity.CrmBanner;
import com.edu.service.CrmBannerService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 后台的banner 管理接口
 * </p>
 *
 * @author testjava
 * @since 2021-07-02
 */
@RestController
@RequestMapping("/educms/banneradmin")
@CrossOrigin
public class BannerAdminController {

	@Autowired
	private CrmBannerService bannerService;

	@GetMapping("/pageBanner/{page}/{limit}")
	public R pageBanner(@PathVariable("page") long page, @PathVariable("limit")long limit){

		Page<CrmBanner> bannerPage = new Page<>(page,limit);
		bannerService.page(bannerPage,null);

		return R.ok().data("items",bannerPage.getRecords()).data("total",bannerPage.getTotal());
	}

	@PostMapping("/addBanner")
	public R addBanner(@RequestBody CrmBanner crmBanner){
		bannerService.save(crmBanner);
		return R.ok();
	}

	@ApiOperation(value = "获取Banner")
	@GetMapping("get/{id}")
	public R get(@PathVariable String id) {
		CrmBanner banner = bannerService.getById(id);
		return R.ok().data("item", banner);
	}

	@ApiOperation(value = "修改Banner")
	@PutMapping("update")
	public R updateById(@RequestBody CrmBanner banner) {
		bannerService.updateById(banner);
		return R.ok();
	}

	@ApiOperation(value = "删除Banner")
	@DeleteMapping("remove/{id}")
	public R remove(@PathVariable String id) {
		bannerService.removeById(id);
		return R.ok();
	}
}

